import 'package:efood_multivendor/controller/user_controller.dart';
import 'package:efood_multivendor/helper/size_config.dart';
import 'package:efood_multivendor/util/dimensions.dart';
import 'package:efood_multivendor/view/base/custom_button.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

class DialogWidget extends StatelessWidget {
  const DialogWidget({
    Key? key,
    required this.context,
    required this.prefs,
    this.title,
    this.image,
    this.description,
    this.fromPage,
  }) : super(key: key);

  final BuildContext context;
  final SharedPreferences prefs;
  final String? title;
  final String? image;
  final String? description;
  final String? fromPage;
  @override
  Widget build(BuildContext context) {
    String wallet = 'wallet';
    String referral = 'referral';
    return WillPopScope(
      onWillPop: () async {
        if (fromPage == wallet) {
          prefs.setBool(
              'newToWallet${Get.find<UserController>().userInfoModel?.phone}',
              false);
          return true;
        } else if (fromPage == referral) {
          prefs.setBool(
              'newToReferral${Get.find<UserController>().userInfoModel?.phone}',
              false);
          return true;
        } else {
          return false;
        }
      },
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Padding(
            padding: EdgeInsets.symmetric(
                horizontal: Dimensions.PADDING_SIZE_LARGE * 2),
            child: Container(
              decoration: const BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(
                  Radius.circular(Dimensions.RADIUS_EXTRA_LARGE),
                ),
              ),
              child: Padding(
                padding: EdgeInsets.all(Dimensions.PADDING_SIZE_LARGE),
                child: Material(
                  child: Column(
                    children: [
                      SizedBox(height: Dimensions.PADDING_SIZE_SMALL),
                      Image.asset('$image'),
                      SizedBox(height: 4.h),
                      Text(
                        title ?? '',
                        style: TextStyle(
                          fontSize: Dimensions.fontSizeLarge * 1.6,
                          fontWeight: FontWeight.bold,
                          color: Theme.of(context).colorScheme.secondary,
                        ),
                        textAlign: TextAlign.center,
                      ),
                      const SizedBox(
                          height: Dimensions.PADDING_SIZE_EXTRA_SMALL),
                      Text(
                        description ?? '',
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontSize: Dimensions.fontSizeDefault * 1.2),
                      ),
                      const SizedBox(height: Dimensions.PADDING_SIZE_LARGE),
                      Row(
                        children: [
                          Expanded(
                              child: CustomButton(
                            buttonText: 'OK',
                            height: 5.h,
                            onPressed: () {
                              Get.back();
                              if (fromPage == wallet) {
                                prefs.setBool(
                                    'newToWallet${Get.find<UserController>().userInfoModel?.phone}',
                                    false);
                              } else if (fromPage == referral) {
                                prefs.setBool(
                                    'newToReferral${Get.find<UserController>().userInfoModel?.phone}',
                                    false);
                              }
                            },
                          )),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
